<?php
//多价格
$bargain_rules = array();
$rule_ids = $_P['rule_id'];
$rule_prices = $_P['rule_price'];
$rule_start = $_P['rule_start'];
$rule_end = $_P['rule_end'];
if (is_array($rule_ids)) {
    foreach ($rule_ids as $key => $value) {
        $d = array('rule_price' => $rule_prices[$key], 'rule_start' => $rule_start[$key], 'rule_end' => $rule_end[$key]);
        $bargain_rules[] = $d;
    }
}
if ($system['is_multiple_bargain'] != 1){
    if($_P['bargain_marketprice'] <= 0){
        return_msg('原价必须设置');
    }
    if($_P['bargain_joinprice'] > $_P['bargain_minprice']){
        return_msg('定金不可大于最低价');
    }
    if($_P['bargain_friendnum'] <= 0 && empty($_P['rule_start'][0])){
        return_msg('砍价规则必须设置');
    }
}else{
    $bargains_name = $_P['bargains_name'];
    if (is_array($bargains_name)) {
        foreach ($bargains_name as $key => $value) {
            $products[]= array(
                'id' => $key,
                'name' => trim($_P['bargains_name'][$key]),
                'status' => intval($_P['bargains_status'][$key]),
                'stock' => intval($_P['bargains_stock'][$key]),
                'detail' => trim($_P['bargains_detail'][$key]),
                'marketprice' => sprintf("%.2f",floatval($_P['bargains_marketprice'][$key])),
                'minprice' => sprintf("%.2f",floatval($_P['bargains_minprice'][$key])),
                'joinprice' => sprintf("%.2f",floatval($_P['bargains_joinprice'][$key])),
                'img' => tomedia($_P['bargains_img'][$key]),
            );
        }
        //当产品大于3时清空后面为空的产品
        if (count($products)>3){
            $products = array_reverse($products);
            foreach ($products as $key => $row) {
                if (empty($row['name'])){
                    unset($products[$key]);
                }else{
                    break;
                }
            }
            $products = array_reverse($products);
        }
    }
}


$tempconfig=array(
    'bargain_products'    => $products,//产品列表
    'bargain_marketprice'    => sprintf("%.2f",floatval($_P['bargain_marketprice'])),//市场价
    'bargain_minprice'    => sprintf("%.2f",floatval($_P['bargain_minprice'])),//最低价
    'bargain_joinprice'    => sprintf("%.2f",floatval($_P['bargain_joinprice'])),//定金
    'bargain_limitstatus' => intval($_P['bargain_limitstatus']),//商品限购状态 0不限制  1限制
    'bargain_limit' => intval($_P['bargain_limit']),//商品限制购买的数量 库存
    'bargain_isdirectbuy' => intval($_P['bargain_isdirectbuy']),//原价购买 0关闭 1开启
    'bargain_showinfojoin' => intval($_P['bargain_showinfojoin']),//显示参于人数还是报名人数
    'bargain_mode' => intval($_P['bargain_mode']),//付款方式 0先付款后砍价-不退 1先付款后砍价-失败退 2砍至最低价下单 3砍价中随时下单
    'bargain_limitfriend' => intval($_P['bargain_limitfriend']),//好友帮砍限制 可以帮砍几人
    'bargain_limittime' => intval($_P['bargain_limittime']),//砍价时长限制
    'bargain_friendnum' => intval($_P['bargain_friendnum']),//固定砍价人数模式  帮砍人数
    'bargain_pricerange' => intval($_P['bargain_pricerange']),//固定砍价人数模式  浮动百分比
    'bargain_rules' => $bargain_rules,
    'bargain_self_grid' => intval($_P['bargain_self_grid']),//报名后是否可以自砍 黄金宝刀 0关闭 1开启
    'bargain_self_share' => intval($_P['bargain_self_share']),//报名后是否可以第一次转发砍一刀 0关闭 1开启
    'bargain_self_dshare' => intval($_P['bargain_self_dshare']),//报名后是否可以第二次转发在分享的上一刀加倍 0关闭 1开启
    'bargain_liucheng'=>tomedia($_P['bargain_liucheng']),
    'bargain_yaoqing'=>tomedia($_P['bargain_yaoqing']),
    'bargain_unpaid_button'=>trim($_P['bargain_unpaid_button']),
    'bargain_paid_button'=>trim($_P['bargain_paid_button']),
    'need_bargain_help_info'=>intval($_P['need_bargain_help_info']),

    'bargain_gift_img'=>tomedia($_P['bargain_gift_img']),//曦尊定制 礼品图
    'bargain_gift_limit'=>intval($_P['bargain_gift_limit']),//曦尊定制 邀请人数
    'bargain_gift_name'=>trim($_P['bargain_gift_name']),//曦尊定制 礼品名称
    'bargain_buy'    => sprintf("%.2f",floatval($_P['bargain_buy'])),// 曦尊定制 支付金额
    'bargain_buy_text'=>trim($_P['bargain_buy_text']),//曦尊定制 未支付按钮文字
    'bargain_order_text'=>trim($_P['bargain_order_text']),//曦尊定制 已支付按钮文字
    'bargain_help_info_tips'=>trim($_P['bargain_help_info_tips']),//曦尊定制 已支付按钮文字
    'bargain_help_info' => intval($_P['bargain_help_info']),


    'bargain_buy_show_money'=>intval($_P['bargain_buy_show_money']),//曦尊定制 未支付按钮文字显示价格

    'bargain_help_gift'=>intval($_P['bargain_help_gift']),//曦尊定制 帮砍有礼
    'bargain_help_gift_other_name'=>trim($_P['bargain_help_gift_other_name']),//曦尊定制 帮砍有礼
    'bargain_help_gift_other_phone'=>trim($_P['bargain_help_gift_other_phone']),//曦尊定制 帮砍有礼
    'bargain_help_gift_first_name'=>trim($_P['bargain_help_gift_first_name']),//曦尊定制 帮砍有礼
    'bargain_help_gift_second_name'=>trim($_P['bargain_help_gift_second_name']),//曦尊定制 帮砍有礼
    'bargain_help_gift_third_name'=>trim($_P['bargain_help_gift_third_name']),//曦尊定制 帮砍有礼
    'bargain_help_gift_first'=>tomedia($_P['bargain_help_gift_first']),//曦尊定制 帮砍有礼礼品图1
    'bargain_help_gift_second'=>tomedia($_P['bargain_help_gift_second']),//曦尊定制 帮砍有礼礼品图2
    'bargain_help_gift_third'=>tomedia($_P['bargain_help_gift_third']),//曦尊定制 帮砍有礼礼品图3
    'bargain_help_gift_icon'=>tomedia($_P['bargain_help_gift_icon']),//曦尊定制 帮砍有礼礼品图3

);
//曦尊开启 不可以开宝刀
if ($system['bargain_gift']==1 && $tempconfig['bargain_self_grid']==1){
    return_msg('曦尊定制和黄金宝刀不可以同时开启');
}
//定金不可以大于原价
if ($tempconfig['bargain_joinprice']>$tempconfig['bargain_marketprice']){
    return_msg('定金不可以大于原价');
}
//价格浮动最大为80
if ($tempconfig['bargain_pricerange']>80){
    return_msg('价格浮动最高为80');
}
$config =array_merge($config,$tempconfig);